package com.lb.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 功能
 *
 * @author libin
 * @since 2.3.0
 */
public class Learning {

    public int[] twoSum(int[] nums, int target) {
        int n = nums.length;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];
    }

    public int[] twoSum1(int[] nums, int target) {
        Map<Integer, Integer> hashtable = new HashMap<Integer, Integer>();
        for (int i = 0; i < nums.length; ++i) {
            if (hashtable.containsKey(target - nums[i])) {
                return new int[]{hashtable.get(target - nums[i]), i};
            }
            hashtable.put(nums[i], i);
        }
        return new int[0];
    }

    public void test1(){
        String c1 = new String("abc");
        String c2 = new String("abc");
        String c3 = c1;
        String c4 = "abc";
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c1)));
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c2)));
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c3)));
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c4)));
        c1 = "sss";
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c1)));
        c1 = "abc";
        System.out.println(String.class.getName() + "@" + Integer.toHexString(System.identityHashCode(c1)));
    }

    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("aa","vv");

        ConcurrentHashMap<String, String> concurrentHashMap = new ConcurrentHashMap<>();
        concurrentHashMap.put("aa","vv");

        System.out.println("asdsdsdsdsdsdsdsdsdsdsdsdsdsda".hashCode());
        System.out.println("ab".hashCode());
        System.out.println("ad".hashCode());
        System.out.println("ag".hashCode());
        System.out.println("ae".hashCode());
        System.out.println("aj".hashCode());

        int h;
        System.out.println((h = "asdsdsdsdsdsdsdsdsdsdsdsdsdsda".hashCode()) ^ (h >>> 16));
        System.out.println((h = "ab".hashCode()) ^ (h >>> 16));
        System.out.println((h = "ad".hashCode()) ^ (h >>> 16));
        System.out.println((h = "ag".hashCode()) ^ (h >>> 16));
        System.out.println((h = "ae".hashCode()) ^ (h >>> 16));
        System.out.println((h = "aj".hashCode()) ^ (h >>> 16));

    }
}